package com.ykh.mybbsdemo.controller;

import com.ykh.mybbsdemo.dao.pojo.po.SysUser;
import com.ykh.mybbsdemo.service.MessageServie;
import com.ykh.mybbsdemo.util.UserThreadLocal;
import com.ykh.mybbsdemo.dao.pojo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-06-08
 * Time: 13:31
 */
@RestController
@RequestMapping("message")
public class MessageController {
    @Autowired
    MessageServie messageServie;
    /**
     * 获取自己的消息列表
     * @param
     * @return
     */
    @PostMapping("list")
    public Result getMessage() {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return messageServie.getMessageList(sysUser);

    }

    /**
     * 推送消息
     * @param
     * @return
     */
    @PostMapping("add")
    public Result addMessage(@RequestParam Long articleId) {
        SysUser sysUser = UserThreadLocal.get();
        if(sysUser == null){
            return Result.fail(405,"用户未登录");
        }
        return messageServie.addMessage(sysUser.getId(), articleId);

    }
}
